package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.Commonication;
import com.ruoyi.wechat.domain.Order;
import com.ruoyi.wechat.service.ICommonicationService;
import com.ruoyi.wechat.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(value = "微信小程序API-营地交流", tags = {"微信小程序API-营地交流"})
@RestController
@RequestMapping("/wechat/commonication")
public class WxCommonicationController extends BaseController {

    @Autowired
    private ICommonicationService commonicationService;


    /**
     * 新增营地订单
     */
    @ApiOperation("新增营地交流")
    @Log(title = "营地交流", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Commonication commonication)
    {
        if(commonication.getContent()==null||commonication.getContent().equals("")){
            return AjaxResult.error("请填写信息");
        }
        System.out.println("commonication: "+commonication);
        commonication.setTime(new Date());
        return toAjax(commonicationService.WxInsertCommonication(commonication));
    }

    /**
     * 查询营地订单列表
     */
    @ApiOperation("查询营地交流列表")
    @GetMapping("/list")
    public TableDataInfo list(Commonication Commonication)
    {
//        startPage();
        List<Commonication> list = commonicationService.selectCommonicationList(Commonication);
        return getDataTable(list);
    }

    /**
     * 修改营地订单
     */
    @ApiOperation("修改营地交流")
    @Log(title = "营地交流", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Commonication Commonication)
    {

         Commonication commonication = commonicationService.selectCommonicationByCommonicationId(Commonication.getCommonicationId());

        return toAjax(commonicationService.updateCommonication(commonication));
    }
}
